package io.finer.erp.jeecg.stock.controller;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.constant.CacheConstant;
import org.jeecg.common.constant.CommonConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.google.api.client.util.Maps;

import cn.hutool.core.collection.CollUtil;
import io.finer.erp.jeecg.bas.entity.BasMaterial;
import io.finer.erp.jeecg.bas.entity.BasMaterialTemp;
import io.finer.erp.jeecg.bas.entity.BasMeasureUnit;
import io.finer.erp.jeecg.bas.entity.ZrkQzOrder;
import io.finer.erp.jeecg.bas.service.IBasMaterialCategoryService;
import io.finer.erp.jeecg.bas.service.IBasMaterialService;
import io.finer.erp.jeecg.bas.service.IBasMaterialTempService;
import io.finer.erp.jeecg.bas.service.IBasMeasureUnitService;
import io.finer.erp.jeecg.bas.service.IZrkDeliverService;
import io.finer.erp.jeecg.bas.service.IZrkQzOrderService;
import io.finer.erp.jeecg.stock.entity.StkInventory;
import io.finer.erp.jeecg.stock.entity.StkIoBill;
import io.finer.erp.jeecg.stock.entity.StkIoBillEntry;
import io.finer.erp.jeecg.stock.service.IScan2ndService;
import io.finer.erp.jeecg.stock.service.IScan3rdService;
import io.finer.erp.jeecg.stock.service.IScan4thService;
import io.finer.erp.jeecg.stock.service.IScanService;
import io.finer.erp.jeecg.stock.service.IStkInventoryService;
import io.finer.erp.jeecg.stock.service.IStkIoBillEntryService;
import io.finer.erp.jeecg.stock.service.IStkIoBillService;
import io.finer.erp.jeecg.stock.service.IStkProcessingOrderService;
import io.finer.erp.jeecg.stock.vo.CompanyModel;
import io.finer.erp.jeecg.stock.vo.ScanIO;
import io.finer.erp.jeecg.stock.vo.ScanInventory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName StkScanController
 * @Description 扫码设备对接系统相关接口
 * @author duanyong
 * @Date 2020-08-15 17:48:13
 * @version 1.0.0
 */
@Api(tags="扫码设备对接系统相关接口")
@RestController
@RequestMapping("/stock/scan")
@Slf4j
public class StkScanController {
	@Autowired
	private IScanService scanService;
	@Autowired
	private IScan2ndService scan2Service;
	@Autowired
	private IScan3rdService scan3Service;
	@Autowired
	private IBasMaterialService basMaterialService;
	@Autowired
	private IBasMaterialCategoryService categoryService;
	@Autowired
	private IBasMeasureUnitService unitService;
	@Autowired
	private IBasMaterialTempService materialTempService;
	@Autowired
	private IStkIoBillService ioBillService;
	@Autowired
	private IStkIoBillEntryService billEntryService;
	@Autowired
	private IZrkDeliverService zrkDeliverService;
	@Autowired
	private IZrkQzOrderService mesService;
	@Autowired
	private IStkProcessingOrderService processingOrderService;
	@Autowired
	private IStkInventoryService inventoryService;
	@Autowired
	private IScan4thService scan4Service;
	
	/**@Description 扫码出入库房具体方法实现
	 * @param code 物料条码
	 * @param operType 1：入库 2：出库
	 * @param number 物料数量
	 * @return
	 * @author duanyong
	 */
	@RequestMapping("/scanCode")
	@AutoLog(value = "扫码出入库")
	@ApiOperation(value = "扫码出入库", notes = "扫码出入库")
	public Result<?> scan(@RequestBody ScanIO scanIo){
		log.info("进入执行出入库操作:" + scanIo.getOperType());
		Result<JSONObject> result = new Result<>();
		result = scanService.inAndOut(scanIo, result);
		
		return result;
	}
	
	@RequestMapping("/materialCheck")
	@AutoLog(value = "复合出库时验证是否配方正确")
	@ApiOperation(value = "复合出库时验证是否配方正确", notes = "复合出库时验证是否配方正确")
	public Result<?> materialCheck(@RequestBody ScanIO scanIo){
		return scanService.materialCheck(scanIo);
	}
	
	@RequestMapping("/findWarehouse")
	@AutoLog(value = "查询仓库")
	@ApiOperation(value = "查询仓库", notes = "查询仓库")
	public Result<?> findWarehouse(@RequestParam(name = "userId", required = true) String userId){
		Result<Object> result = new Result<>();
		return this.scanService.findWarehouse(userId, result);
	}
	
	/**
	 * @Description 扫码盘点操作
	 * @param list
	 * @return
	 * Create at: 2020-08-21 15:35:57
	 * @author: duanyong
	 * Revision:
	 *    2020-08-21 15:35:57 - first revision by duanyong
	 *        
	 */
	@RequestMapping("/inventory")
	@AutoLog(value = "扫码盘点")
	@ApiOperation(value = "扫码盘点", notes = "扫码盘点")
	public Result<?> inventory(@RequestBody ScanInventory inventory){
		Result<Object> result = new Result<>();
		return this.scanService.inventory(inventory, result);
	}
	
	
	/**
	 * @Description 查询客户
	 * @param userId
	 * @return
	 * Create at: 2020-08-22 16:41:25
	 * @author: duanyong
	 * Revision:
	 *    2020-08-22 16:41:25 - first revision by duanyong
	 *        
	 */
	@RequestMapping("/findCustomer")
	@AutoLog(value = "查询客户")
	@ApiOperation(value = "查询客户", notes = "查询客户")
	public Result<?> findCustomer(@RequestParam(name = "userId", required = true) String userId){
		Result<Object> result = new Result<>();
		return this.scanService.findCustomer(userId, result);
	}
	
    /**
     * @Description 批量生成物料
     * @param categoryId 物料分类ID
     * @param number 物料数量
     * @return
     * Create at: 2020-08-31 11:26:01
     * @author: duanyong
     * Revision:
     *    2020-08-31 11:26:01 - first revision by duanyong
     *        
     */
    //TODO
    @AutoLog(value = "物料-批量添加")
	@ApiOperation(value="物料-批量添加", notes="物料-批量添加")
	@GetMapping(value = "/batchAdd")
    public Result<?> batchAdd(@RequestParam(name="batchCategoryId", required=true)String batchCategoryId
    		, @RequestParam(name="batchNum", required=true)Integer batchNum
    		, @RequestParam(name="userId")String userId
    		, @RequestParam(name="userName")String userName
    		, @RequestParam(name="orgCode")String orgCode
    		, @RequestParam(name="isAccessories")String isAccessories
    		, @RequestParam(name="model", defaultValue = "")String model, ScanIO scanIo){
    	if(StringUtils.isBlank(isAccessories) || "0".equals(isAccessories)) {
    		return this.basMaterialService.batchAdd(batchCategoryId, batchNum, userName);
    	} else if("2".equals(isAccessories)) {
    		return this.basMaterialService.batchAdd(scanIo);
    	} else {
    		return basMaterialService.batchAddAccessories(batchCategoryId, batchNum, userName, model);
    	}
    	
    }
    
	@GetMapping("/getMaterial")
	@AutoLog(value = "查询物料分类")
	@ApiOperation(value = "查询物料分类", notes = "查询物料分类")
    public Result<?> getMaterial(@RequestParam(name = "userId", required = true) String userId){
		Result<Object> result = new Result<>();
		return this.scanService.getMaterial(userId, result);
	}
	
	@GetMapping("/getUnit")
	@AutoLog(value = "查询单位")
	@ApiOperation(value = "查询单位", notes = "查询单位")
	public Result<?> getUnit(@RequestParam(name = "userId", required = true) String userId){
		Result<Object> result = new Result<>();
		return this.scanService.getUnit(userId, result);
	}
	
	@GetMapping("/getSupplier")
	@AutoLog(value = "查询供应商")
	@ApiOperation(value = "查询供应商", notes = "查询供应商")
	public Result<?> getSupplier(@RequestParam(name = "userId", required = true) String userId){
		Result<Object> result = new Result<>();
		return this.scanService.getSupplier(userId, result);
	}
	
	/**
	 * @Description 查询源单
	 * @param userId
	 * @param orderType 单据类型 0：生产订单 1：销售订单 2：采购单
	 * @return
	 * Create at: 2020-10-07 10:58:30
	 * @author: duanyong
	 * Revision:
	 *    2020-10-07 10:58:30 - first revision by duanyong
	 *        
	 */
	@GetMapping("/getOrder")
	@AutoLog(value = "查询源单")
	@ApiOperation(value = "查询源单", notes = "查询源单")
	public Result<?> getOrder(@RequestParam(name = "userId", required = true) String userId,
			@RequestParam(name = "orderType", required = true) Integer orderType,
			@RequestParam(name = "inOutType", required = false) String inOutType){
		Result<Object> result = new Result<>();
		
		return this.scan3Service.getOrder(userId, orderType, result, inOutType);
	}
	
	/**
	 * @Description 根据生产订单维护工序信息
	 * @param orderId
	 * @return
	 * Create at: 2020-10-07 10:57:24
	 * @author: duanyong
	 * Revision:
	 *    2020-10-07 10:57:24 - first revision by duanyong
	 *        
	 */
	@GetMapping("/getProcedure")
	@AutoLog(value = "查询工序")
	@ApiOperation(value = "查询工序", notes = "查询工序")
	public Result<?> getProcedure(@RequestParam(name = "orderId", required = true)String orderId,
			@RequestParam(name = "type", defaultValue = "1")String type){
		Result<?> r = this.scanService.getProcedure(orderId);
		return r;
	}
	
	/**
	 * @Description 生产人员维护生产出的物料信息。
	 * @param scanIo
	 * @return
	 * Create at: 2020-10-07 10:57:38
	 * @author: duanyong
	 * Revision:
	 *    2020-10-07 10:57:38 - first revision by duanyong
	 *        
	 */
	@PostMapping("/productInfo")
	@AutoLog(value = "维护物料信息")
	@ApiOperation(value = "维护物料信息", notes = "维护物料信息")
	public Result<?> productInfo(@RequestBody ScanIO scanIo){
		return scan2Service.productInfo(scanIo);
	}
	
	@GetMapping("/getBCPCategory")
	@AutoLog(value = "查询半成品分类")
	@ApiOperation(value = "查询半成品分类", notes = "查询半成品分类")
	public Result<?> getBCPCategory(){
		return categoryService.getCengPinCategory();
	}
	
	@GetMapping("/getCPCategory")
	@AutoLog(value = "查询产品分类")
	@ApiOperation(value = "查询产品分类", notes = "查询产品分类")
	public Result<?> getCPCategory(){
		return categoryService.getCengPinCategory();
	}
	
	/**
	 * @Description 查询原材料分类
	 * @return
	 * Create at: 2020-10-12 13:43:26
	 * @author: duanyong
	 * Revision:
	 *    2020-10-12 13:43:26 - first revision by duanyong
	 *        
	 */
	@GetMapping("/getYCLCategory")
	@AutoLog(value = "查询原材料分类")
	@ApiOperation(value = "查询原材料分类", notes = "查询原材料分类")
	public Result<?> getYCLCategory(){
		return categoryService.getMaterialCategory(true);
	}
	
	@GetMapping("/getReturnStockMaterialByCode")
	@AutoLog(value = "生产退库查询物料信息")
	@ApiOperation(value = "生产退库查询物料信息", notes = "生产退库查询物料信息")
	public Result<?> getReturnStockMaterialByCode(@RequestParam(name = "code", required = true)String code){
		BasMaterial material = this.basMaterialService.getMaterialByCode(code);
		if(null == material) {
			return Result.error("未找到相关物料");
		}
		BasMeasureUnit unit = unitService.getById(material.getUnitId());
		if(unit!=null) {
			material.setUpdateBy(unit.getName());//暂时将获取到的单位名称存储在updateBy变量中
		}
		BasMaterialTemp temp = this.materialTempService.getByCode(code);
		BigDecimal amount = temp.getAmount();
		if(amount != null) {
			material.setCreateBy(amount.toString());
		} else {
			String unitId = material.getUnitId();
			boolean flag = false;
			if(StringUtils.isNotBlank(unitId) && null != unit) {
				String name = unit.getName();
				if("平方".equals(name)) {
					BigDecimal square = temp.getSquare();
					if(null != square) {
						material.setCreateBy(square.toString());
					} else {
						flag = true;
					}
				} else {
					flag = true;
				}
			} else {
				flag = true;
			}
			if(flag) {
				material.setCreateBy("");
			}
		}
		return Result.ok(material);
	}
	
	
	@GetMapping("/getMaterialByCode")
	@AutoLog(value = "查询物料信息")
	@ApiOperation(value = "查询物料信息", notes = "查询物料信息")
	public Result<?> getMaterialByCode(@RequestParam(name = "code", required = true)String code, @RequestParam(name = "orderId", required = true) String orderId){
		BasMaterial material = this.basMaterialService.getMaterialByCode(code);
		if(null == material) {
			material = materialTempService.tempToMaterial(code);
		}
		if(material != null) {
			BasMeasureUnit unit = unitService.getById(material.getUnitId());
			if(unit!=null) {
				material.setUpdateBy(unit.getName());//暂时将获取到的单位名称存储在updateBy变量中
			}
			BasMaterialTemp temp = this.materialTempService.getByCode(code);
			BigDecimal amount = temp.getAmount();
			if(amount != null) {
				material.setCreateBy(amount.toString());
			}
			StkIoBill bill = this.ioBillService.getById(orderId);
			if(null != bill) {
				List<StkIoBillEntry> entrys = this.billEntryService.selectByMainId(bill.getId());
				if(CollUtil.isNotEmpty(entrys)) {
					for(StkIoBillEntry entry : entrys) {
						String categoryId = entry.getMaterialId();
						if(material.getCategoryId().equals(categoryId)){
							BigDecimal settlePrice = entry.getSettlePrice();
							if(null != settlePrice && null != amount) {
								settlePrice = settlePrice.multiply(amount);
								settlePrice = settlePrice.setScale(2, BigDecimal.ROUND_HALF_UP);
								material.setCodeImg(settlePrice.toString());//存放价格
								break;
							}
						}
					}
				}
			}
		} else {
			return Result.error("未查询到物料信息。");
		}
		return Result.ok(material);
	}
	
	@GetMapping("/getTheMaterialByCode")
	@AutoLog(value = "根据Code获取物料信息")
	@ApiOperation(value = "根据Code获取物料信息", notes = "根据Code获取物料信息")
	public Result<BasMaterial> getTheMaterialByCode(@RequestParam(name = "code", required = true)String code) {
		BasMaterial material = this.basMaterialService.getMaterialByCode(code);
		Result<BasMaterial> result = new Result<>();
		if(null == material) {
			result.error500("未查到相关物料");
		} else {
			result.setCode(CommonConstant.SC_OK_200);
			result.setSuccess(Boolean.TRUE);
			List<StkInventory> list = this.inventoryService.lambdaQuery().eq(StkInventory::getMaterialId, material.getId())
			.gt(StkInventory::getQty, BigDecimal.ZERO).list();
			if(CollUtil.isNotEmpty(list)) {
				StkInventory inventory = list.get(0);
				material.setQuantity(inventory.getQty());
			}
			result.setResult(material);
		}
		return result;
	}
	
	@GetMapping("/getInMaterialByCode")
	@AutoLog(value = "入库时查询物料的信息")
	@ApiOperation(value = "入库时查询物料的信息", notes = "入库时查询物料的信息")
	public Result<?> getInMaterialByCode(@RequestParam(name = "code", required = true)String code){
		BasMaterial material = this.basMaterialService.getMaterialByCode(code);
		if(null == material) {
			material = materialTempService.getTemMaterial(code);
		}
		if(null == material) {
			return Result.error("未查询到物料。");
		}
		BasMeasureUnit unit = unitService.getById(material.getUnitId());
		if(unit!=null && StringUtils.isNotBlank(unit.getName())){
			material.setUpdateBy(unit.getName());//暂时将获取到的单位名称存储在updateBy变量中
		}
		Map<String, Object> result = Maps.newLinkedHashMap();
		result.put("material", material);
		StkIoBill materialBill = this.ioBillService.getByMaterialId(material.getId());
		result.put("bill", materialBill);
		BasMaterialTemp temp = this.materialTempService.getByCode(code);
		String orderId = temp.getOrderId();
		ZrkQzOrder mes  = this.mesService.getById(orderId);
		result.put("order", mes);
		
		return Result.ok(result);
	}
	
	@PostMapping("/tray")
	@AutoLog(value = "物料关联托盘")
	@ApiOperation(value = "物料关联托盘", notes = "物料关联托盘")
	public Result<?> tray(@RequestBody ScanIO scanIo){
		return this.scanService.tray(scanIo);
	}
	
	@PostMapping("/trayTake")
	@AutoLog(value = "上托盘")
	@ApiOperation(value = "上托盘", notes = "上托盘")
	public Result<?> trayTake(@RequestBody ScanIO scanIo){
		return this.scan3Service.trayTake(scanIo);
	}
	
	@PostMapping("/trayTakeOff")
	@AutoLog(value = "下托盘")
	@ApiOperation(value = "下托盘", notes = "下托盘")
	public Result<?> trayTakeOff(@RequestBody ScanIO scanIo){
		return this.scan3Service.trayTakeOff(scanIo);
	}
	
	@PostMapping("/getMaterialTray")
	@AutoLog(value = "查询物料所在托盘")
	@ApiOperation(value = "查询物料所在托盘", notes = "查询物料所在托盘")
	public Result<?> getMaterialTray(@RequestBody ScanIO scanIo){
		return this.scan3Service.getMaterialTray(scanIo);
	}
	
	@PostMapping("/shipment")
	@AutoLog(value = "出货")
	@ApiOperation(value = "出货", notes = "出货")
	public Result<?> shipment(@RequestBody ScanIO scanIo){
		return this.scanService.shipment(scanIo);
	}
	
	@PostMapping("/getSaleOutBill")
	@AutoLog(value = "获取销售出库单")
	@ApiOperation(value = "获取销售出库单", notes = "获取销售出库单")
	public Result<?> getSaleOutBill(@RequestParam(name = "userId", required = true) String userId, @RequestParam(name = "code", required = true)String code){
		return scanService.getSaleOutBill(code);
	}
	
	@AutoLog(value = "获取销售单")
	@PostMapping("/getSaleOutBillList")
	public Result<?> getSaleOutBillList(@RequestParam(name = "userId", required = true) String userId){
		return this.ioBillService.getSaleOutBillList(100);
	}
	
	@AutoLog(value = "获取出入库记录")
	@PostMapping("/getBillShipmentList")
	public Result<?> getBillShipmentList(@RequestParam(name = "userId", required = true) String userId, @RequestParam(name = "billNo", required = true) String billNo){
		return this.zrkDeliverService.getBillShipmentList(billNo);
	}
	
	/**
	 * @Description 获取物流公司
	 * @param userId
	 * @return
	 * Create at: 2020-10-24 09:55:56
	 * @author: duany
	 * Revision:
	 *    2020-10-24 09:55:56 - first revision by duany
	 *        
	 */
	@AutoLog(value = "获取物流公司")
	@GetMapping("/getCompany")
	public Result<?> getCompany(@RequestParam(name = "userId", required = true) String userId){
		List<CompanyModel> list = scan2Service.getCompany();
		return Result.ok(list);
	}
	
	/**
	 * @Description 根据传入的code判断是否是出货单如果是 则返回ID
	 * @param code
	 * @return
	 * Create at: 2021-04-23 11:54:50
	 * @author: duany
	 * Revision:
	 *    2021-04-23 11:54:50 - first revision by duany
	 *        
	 */
	@AutoLog(value = "根据传入的code判断是否是出货单如果是 则返回ID")
	@GetMapping("/getShipmentByCode")
	public Result<?> getShipmentByCode(@RequestParam(name = "code", required = true) String code){
		Map<String, String> result = zrkDeliverService.getShipmentByCode(code);
		return Result.ok(result);
	}
	
	/**
	 * @Description 代加工入库时查询代加工移库的单据
	 * @param userId
	 * @return
	 * Create at: 2020-11-02 11:01:31
	 * @author: duany
	 * Revision:
	 *    2020-11-02 11:01:31 - first revision by duany
	 *        
	 */
	@PostMapping("/getProcessingOrder")
	public Result<?> getProcessingOrder(@RequestParam(name= "userId") String userId){
		if(StringUtils.isBlank(userId)) {
			return Result.error(500, "用户验证失败");
		}
		return this.scan2Service.getProcessingOrder();
	}
	
	/**
	 * @Description 库存调拨时检查物料编码所对应的物料，及获取物料所属的仓库信息。
	 * @param scanIo
	 * @return
	 * Create at: 2020-11-16 15:47:14
	 * @author: duany
	 * Revision:
	 *    2020-11-16 15:47:14 - first revision by duany
	 *        
	 */
	@AutoLog(value = "库存调拨时检查物料编码所对应的物料，及获取物料所属的仓库信息。")
	@GetMapping("/getMaterialWarehouse")
	public Result<?> getMaterialWarehouse(ScanIO scanIo){
		if(StringUtils.isBlank(scanIo.getUserId())) {
			return Result.error(500, "用户验证失败");
		}
		return this.scan2Service.getMaterialWarehouse(scanIo);
	}
	
	/**
	 * @Description 库存调拨
	 * @param scanIo
	 * @return
	 * Create at: 2020-11-16 16:13:45
	 * @author: duany
	 * Revision:
	 *    2020-11-16 16:13:45 - first revision by duany
	 *        
	 */
	@AutoLog(value = "PDA库存调拨")
	@PostMapping("/transfer")
	public Result<?> transfer(@RequestBody ScanIO scanIo){
		return this.scan2Service.transfer(scanIo);
	}
	
	/**
	 * @Description 查询检查员
	 * @return
	 * Create at: 2020-11-28 12:03:51
	 * @author: duany
	 * Revision:
	 *    2020-11-28 12:03:51 - first revision by duany
	 *        
	 */
	@AutoLog(value = "查询检查员")
	@GetMapping("/inspector")
	public Result<?> inspector(){
		return this.scan2Service.inspector();
	}
	
	/**
	 * @Description 根据编码溯源
	 * @param code
	 * @return
	 * Create at: 2020-12-01 11:00:51
	 * @author: duany
	 * Revision:
	 *    2020-12-01 11:00:51 - first revision by duany
	 *        
	 */
	@AutoLog(value = "根据编码溯源")
	@PostMapping("/trace")
	public Result<?> trace(@RequestParam(name = "code")String code){
		return this.scan2Service.trace(code);
	}
	
	/**
	 * @Description 根据工序查询对应的mes单
	 * @param processId 工序ID
	 * @return
	 * Create at: 2021-02-20 09:51:17
	 * @author: duany
	 * Revision:
	 *    2021-02-20 09:51:17 - first revision by duany
	 *        
	 */
	@AutoLog(value = "根据工序查询对应的mes单")
	@GetMapping("/getProcessMes")
	public Result<?> getProcessMes(@RequestParam("processId")String processId){
		return this.scan3Service.getProcessMes(processId);
	}
	
	/**
	 * @Description 出入库时查询mes单
	 * @param type
	 * @param inOutType
	 * @return
	 * Create at: 2021-02-20 13:24:39
	 * @author: duany
	 * Revision:
	 *    2021-02-20 13:24:39 - first revision by duany
	 *        
	 */
	@AutoLog(value = "出入库时查询mes单")
	@GetMapping("/getInOutMes")
	public Result<?> getInOutMes(@RequestParam("type")Integer type, @RequestParam("inOutType")Integer inOutType){
		return this.scan3Service.getInOutMes(type, inOutType);
	}
	
	/**
	 * @Description 获取MES单对应的物料
	 * @param mesId
	 * @return
	 * Create at: 2021-04-23 11:52:22
	 * @author: duany
	 * Revision:
	 *    2021-04-23 11:52:22 - first revision by duany
	 *        
	 */
	@AutoLog(value = "获取MES单对应的物料")
	@GetMapping("/getMesCategory")
	public Result<?> getMesCategory(@RequestParam("mesId")String mesId){
		return this.scan3Service.getMesCategory(mesId);
	}
	
	/**
	 * @Description 
	 * @param code
	 * @return
	 * Create at: 2021-04-23 11:51:46
	 * @author: duany
	 * Revision:
	 *    2021-04-23 11:51:46 - first revision by duany
	 *        
	 */
	@AutoLog(value = "PDA查看物料")
	@GetMapping("/seeMaterial")
	public Result<?> seeMaterial(@RequestParam("code")String code){
		return this.scan3Service.seeMaterial(code);
	}
	
	/**
	 * @Description 
	 * @param orderId
	 * @return
	 * Create at: 2021-04-23 11:51:35
	 * @author: duany
	 * Revision:
	 *    2021-04-23 11:51:35 - first revision by duany
	 *        
	 */
	@AutoLog(value = "获取MES单的客户信息")
	@GetMapping("/getMesCustomer")
	public Result<?> getMesCustomer(@RequestParam("orderId") String orderId){
		return this.scan3Service.getMesCustomer(orderId);
	}
	
	/**
	 * @Description 
	 * @param code
	 * @return
	 * Create at: 2021-04-23 11:51:39
	 * @author: duany
	 * Revision:
	 *    2021-04-23 11:51:39 - first revision by duany
	 *        
	 */
	@AutoLog(value = "获取物料关联的mes单")
	@GetMapping("/getMaterialOrder")
	public Result<?> getMaterialOrder(@RequestParam("code") String code){
		return this.scan3Service.getMaterialOrder(code);
	}
	
	/**
	 * @Description 扫码删除物料
	 * @param list
	 * @return
	 * Create at: 2021-02-20 10:23:41
	 * @author: duany
	 * Revision:
	 *    2021-02-20 10:23:41 - first revision by duany
	 *        
	 */
	@AutoLog(value = "扫码删除物料")
	@PostMapping("/delMaterial")
	public Result<?> delMaterial(@RequestBody ScanIO scanIo){
		return this.scan3Service.delMaterial(scanIo);
	}
	
	/**
	 * @Description 批量添加胶水物料
	 * @param scanIo
	 * @return
	 * Create at: 2021-03-06 11:02:23
	 * @author: duany
	 * Revision:
	 *    2021-03-06 11:02:23 - first revision by duany
	 *        
	 */
	@AutoLog(value = "批量添加胶水物料")
	@PostMapping("/batchAddGlue")
	public Result<?> batchAddGlue(@RequestBody ScanIO scanIo){
		return this.scan3Service.batchAddGlue(scanIo);
	}
	
	/**
	 * @Description 查询制胶MES
	 * @param inOutType
	 * @return
	 * Create at: 2021-03-09 16:44:33
	 * @author: duany
	 * Revision:
	 *    2021-03-09 16:44:33 - first revision by duany
	 *        
	 */
	@AutoLog(value = "查询制胶MES")
	@GetMapping("/getGlueMes")
	public Result<?> getGlueMes(Integer inOutType){
		return this.scan3Service.getGlueMes(inOutType);
	}
	
	@AutoLog(value = "获取物料分类ID")
	@GetMapping("/categoryUnit")
	public Result<?> categoryUnit(String categoryId){
		return this.scan3Service.categoryUnit(categoryId);
	}
	
	/**
	 * @Description 销售出库单据打印
	 * @param scanIo
	 * @return
	 * Create at: 2021-04-09 16:42:26
	 * @author: duany
	 * Revision:
	 *    2021-04-09 16:42:26 - first revision by duany
	 *        
	 */
	@AutoLog(value = "销售出库单据打印")
	@PostMapping("/printSalOut")
	public Result<?> printSalOut(@RequestBody ScanIO scanIo){
		return this.scan3Service.printSalOut(scanIo);
	}
	
	@AutoLog(value = "查询订单详情和订单出库详情")
	@ApiOperation(value="查询订单详情和订单出库详情", notes="查询订单详情和订单出库详情")
	@GetMapping("/getOrderSaleOutInfo")
	public Result<?> getOrderSaleOutInfo(String orderId){
		return this.scan3Service.getOrderSaleOutInfo(orderId);
	}
	
	@AutoLog(value = "查询客户订单详情和订单出库详情")
	@ApiOperation(value="查询客户订单详情和订单出库详情", notes="查询客户订单详情和订单出库详情")
	@GetMapping("/getCustomerOrderSaleOutInfo")
	public Result<?> getCustomerOrderSaleOutInfo(String customerId){
		return this.scan3Service.getCustomerOrderSaleOutInfo(customerId);
	}
	
	/**
	 * @Description 代加工出库
	 * @param scan
	 * @return
	 * Create at: 2021-04-20 16:09:17
	 * @author: duany
	 * Revision:
	 *    2021-04-20 16:09:17 - first revision by duany
	 *        
	 */
	@PostMapping("/processingOut")
	@AutoLog(value = "代加工出库")
	public Result<?> processingOut(@RequestBody ScanIO scan){
		log.info("执行代加工出库");
		return this.scan3Service.processingOut(scan);
	}
	
	/**
	 * @Description 代加工出库 获取代加工单
	 * @return
	 * Create at: 2021-04-22 10:11:01
	 * @author: duany
	 * Revision:
	 *    2021-04-22 10:11:01 - first revision by duany
	 *        
	 */
	@PostMapping("/processingOutGetOrder")
	@AutoLog(value = "代加工出库 获取代加工单")
	public Result<?> processingOutGetOrder(){
		return this.processingOrderService.processingOutGetOrder();
	}
	
	/**
	 * @Description 代加工入库 获取代加工单
	 * @return
	 * Create at: 2021-04-22 10:11:18
	 * @author: duany
	 * Revision:
	 *    2021-04-22 10:11:18 - first revision by duany
	 *        
	 */
	@AutoLog(value = "代加工入库 获取代加工单")
	@PostMapping("/processingInGetOrder")
	public Result<?> processingInGetOrder(){
		return this.processingOrderService.processingInGetOrder();
	}
	
	/**
	 * @Description 查询代加工单关联的物料分类
	 * @param processingId
	 * @return
	 * Create at: 2021-04-23 11:45:21
	 * @author: duany
	 * Revision:
	 *    2021-04-23 11:45:21 - first revision by duany
	 *        
	 */
	@GetMapping("/getProcessingCategory")
	@AutoLog(value = "查询代加工单关联的物料分类")
	public Result<?> getProcessingCategory(String processingId){
		return this.processingOrderService.getProcessingCategory(processingId);
	}
	
	/**
	 * @Description 代加工条码打印
	 * @param scan
	 * @return
	 * Create at: 2021-04-23 14:37:10
	 * @author: duany
	 * Revision:
	 *    2021-04-23 14:37:10 - first revision by duany
	 *        
	 */
	@PostMapping("/processingPrint")
	@AutoLog(value = "代加工条码打印")
	public Result<?> processingPrint(@RequestBody ScanIO scan){
		return this.scan3Service.processingPrint(scan);
	}
	
	/**
	 * @Description 根据编码信息查询物料
	 * @param code
	 * @return
	 * Create at: 2021-05-07 13:51:48
	 * @author: duany
	 * Revision:
	 *    2021-05-07 13:51:48 - first revision by duany
	 *        
	 */
	@GetMapping("/initMaterial")
	public Result<?> initMaterial(String code){
		return scan3Service.initMaterial(code);
	}
	
	/**
	 * @Description 获取所有用户
	 * @return
	 * Create at: 2021-05-07 15:45:03
	 * @author: duany
	 * Revision:
	 *    2021-05-07 15:45:03 - first revision by duany
	 *        
	 */
	@GetMapping("/getAllCustomer")
	public Result<?> getAllCustomer(){
		return scan3Service.getAllCustomer();
	}
	
	/**
	 * @Description 重新打码
	 * @param scan
	 * @return
	 * Create at: 2021-05-12 11:23:28
	 * @author: duany
	 * Revision:
	 *    2021-05-12 11:23:28 - first revision by duany
	 *        
	 */
	@PostMapping("/rePrint")
	@AutoLog(value = "重新打码")
	public Result<?> rePrint(@RequestBody ScanIO scan){
		return scan3Service.rePrint(scan);
	}
	
	/**
	 * @Description 扫描物料添加到log表
	 * @param scan
	 * @return
	 * Create at: 2021-05-12 11:24:29
	 * @author: duany
	 * Revision:
	 *    2021-05-12 11:24:29 - first revision by duany
	 *        
	 */
	@PostMapping("/scanMaterial")
	@AutoLog(value = "扫描物料添加到log表")
	public Result<?> scanMaterial(@RequestBody ScanIO scan){
		return scan3Service.scanMaterial(scan);
	}
	
	/**
	 * @Description 查看MES单出库物料是否是扫码的物料
	 * @param scan
	 * @return
	 * Create at: 2021-06-21 16:32:43
	 * @author: duany
	 * Revision:
	 *    2021-06-21 16:32:43 - first revision by duany
	 *        
	 */
	@PostMapping("/checkMesMaterial")
	@AutoLog(value = "查看MES单出库物料是否是扫码的物料")
	public Result<?> checkMesMaterial(@RequestBody ScanIO scan){
		return scan3Service.checkMesMaterial(scan);
	}
	
	/**
	 * @Description 查询MES单
	 * @param procedureId 工序ID
	 * @return
	 * Create at: 2021-06-22 16:27:53
	 * @author: duany
	 * Revision:
	 *    2021-06-22 16:27:53 - first revision by duany
	 *        
	 */
	@GetMapping("/getCheckMes")
	public Result<?> getCheckMes(String procedureId){
		return scan3Service.getCheckMes(procedureId);
	}
	
	@PostMapping("/rePrintPurchase")
	@AutoLog(value = "重新打码采购标签")
	@CacheEvict(value= {CacheConstant.SYS_DICT_TABLE_CACHE,CacheConstant.BAS_MATERIAL_CATEGORY}, allEntries=true)
	public Result<Map<String, Object>> rePrintPurchase(@RequestBody ScanIO scan){
		return this.scan3Service.rePrintPurchase(scan);
	}
	
	@PostMapping("/rePrintFh")
	@AutoLog(value = "重新打码复合标签")
	@CacheEvict(value= {CacheConstant.SYS_DICT_TABLE_CACHE,CacheConstant.BAS_MATERIAL_CATEGORY}, allEntries=true)
	public Result<Map<String, Object>> rePrintFh(@RequestBody ScanIO scan){
		return scan3Service.rePrintFh(scan);
	}
	
	@PostMapping("/rePrintFq")
	@AutoLog(value = "重新打码分切标签")
	@CacheEvict(value= {CacheConstant.SYS_DICT_TABLE_CACHE,CacheConstant.BAS_MATERIAL_CATEGORY}, allEntries=true)
	public Result<Map<String, Object>> rePrintFq(@RequestBody ScanIO scan){
		return this.scan3Service.rePrintFq(scan);
	}
	
	@PostMapping("/rePrintQz")
	@AutoLog(value = "重新打码切张标签")
	@CacheEvict(value= {CacheConstant.SYS_DICT_TABLE_CACHE,CacheConstant.BAS_MATERIAL_CATEGORY}, allEntries=true)
	public Result<Map<String, Object>> rePrintQz(@RequestBody ScanIO scan){
		return this.scan3Service.rePrintQz(scan);
	}
	
	@GetMapping("/rePrintCategory")
	public Result<?> rePrintCategory(){
		return this.scan3Service.rePrintCategory();
	}
	
	@GetMapping("/rePrintGetMaterial")
	public Result<?> rePrintGetMaterial(String code){
		return this.scan3Service.rePrintGetMaterial(code);
	}
	
	/**
	 * @Description 根据编码获取客户信息
	 * @param code
	 * @return
	 * Create at: 2021-08-26 10:37:07
	 * @author: duany
	 * Revision:
	 *    2021-08-26 10:37:07 - first revision by duany
	 *        
	 */
	@GetMapping("/getCodeCustomer")
	public Result<?> getCodeCustomer(String code){
		return this.scan3Service.getCodeCustomer(code);
	}
	
	/**
	 * @Description 采购退货时查询物料信息
	 * @param code
	 * @return
	 * Create at: 2021-09-23 10:51:58
	 * @author: duany
	 * Revision:
	 *    2021-09-23 10:51:58 - first revision by duany
	 *        
	 */
	@GetMapping("/purchaseReturnMaterial")
	public Result<?> purchaseReturnMaterial(String code){
		return this.scan3Service.purchaseReturnMaterial(code);
	}
	
	/**
	 * @Description 采购退货
	 * @param code
	 * @return
	 * Create at: 2021-09-23 10:51:58
	 * @author: duany
	 * Revision:
	 *    2021-09-23 10:51:58 - first revision by duany
	 *        
	 */
	@PostMapping("/purchaseReturn")
	public Result<?> purchaseReturn(@RequestBody ScanIO scan){
		return this.scan3Service.purchaseReturn(scan);
	}
	
	/**
	 * @Description 切张拆包查询物料
	 * @param code
	 * @return
	 * Create at: 2021-09-27 09:42:05
	 * @author: duany
	 * Revision:
	 *    2021-09-27 09:42:05 - first revision by duany
	 *        
	 */
	@GetMapping("/splitQzMaterial")
	public Result<?> splitQzMaterial(String code){
		return this.scan3Service.splitQzMaterial(code);
	}
	
	/**
	 * @Description 切张拆包
	 * @param scan
	 * @return
	 * Create at: 2021-09-27 11:00:57
	 * @author: duany
	 * Revision:
	 *    2021-09-27 11:00:57 - first revision by duany
	 *        
	 */
	@PostMapping("/splitQz")
	@AutoLog(value = "PDA-切张拆包")
	public Result<?> splitQz(@RequestBody ScanIO scan){
		return this.scan3Service.splitQz(scan);
	}
	
	/**
	 * @Description 制胶重新打码时查询物料
	 * @param code
	 * @return
	 * Create at: 2021-09-30 10:09:45
	 * @author: duany
	 * Revision:
	 *    2021-09-30 10:09:45 - first revision by duany
	 *        
	 */
	@GetMapping("/rePrintZjMaterial")
	public Result<?> rePrintZjMaterial(String code){
		return scan4Service.rePrintZjMaterial(code);
	}
}
